
# 1. 基础语法练习
# 变量声明与类型
name = 'John'
age = 30
is_student = True
height = 1.75

# 类型转换
try:
    age_str = str(age)
    height_int = int(height)
    print(f"类型转换: age_str={age_str}, height_int={height_int}")
except Exception as e:
    print(f"类型转换错误: {e}")

# 2. 函数练习
def greet(name, age):
    """打招呼函数"""
    return f"你好, {name}! 你今年{age}岁了。"

print(greet(name, age))

# 3. 数据结构练习
# 列表
fruits = ['apple', 'banana', 'orange']
fruits.append('pear')
print(f"水果列表: {fruits}")

# 字典
person = {
    'name': name,
    'age': age,
    'is_student': is_student
}
print(f"个人信息: {person}")

# 4. 类与对象
class Student:
    def __init__(self, name, age):
        self.name = name
        self.age = age
    
    def introduce(self):
        return f"我是{self.name}, 今年{self.age}岁"

student = Student(name, age)
print(student.introduce())